const router = require('koa-router')(),
      mysql = require('mysql2/promise'),
      { user } = require('../models');

router.prefix('/api/kdoing/user');

router.get('/gethealthdata/:userid', async (ctx, next) => {
  var { userid } = ctx.params;
  ctx.body = await user.getHealthdataByUserid(userid);
});
router.get('/getUsers', async (ctx, next) => {
  ctx.body = await user.getUsers();
});
router.post('/addhealthdata', async (ctx, netx) => {
  var { user_id,height,weight,bust,waistline,hipline,bmi } = ctx.request.body;
  ctx.body = await user.addHealthdata(user_id,height,weight,bust,waistline,hipline,bmi);
});
router.post('/adduser', async (ctx, netx) => {
  console.log(ctx.request.body)
  var { openid, user_name, user_avatar, user_sex} = ctx.request.body;
  ctx.body = await user.addUser(openid, user_name, user_avatar, user_sex);
});
router.delete('/deluser/:user_id', async (ctx, next) => {
  var { user_id } = ctx.params;
  ctx.body = await user.deleteUserByUserid(user_id);
});
router.get('/getuserid/:user_name', async (ctx, next) => {
  var { user_name } = ctx.params;
  ctx.body = await user.getUseridByUsername(user_name);
});
router.get('/getcares/:user_id', async (ctx, next) => {
  var { user_id } = ctx.params;
  ctx.body = await user.getCares(user_id);
});
router.get('/getfans/:user_id', async (ctx, next) => {
  var { user_id } = ctx.params;
  ctx.body = await user.getFans(user_id);
});
router.post('/tocare', async (ctx, netx) => {
  var { user_id, care_id} = ctx.request.body;
  console.log(ctx.request.body)
  ctx.body = await user.toCare(user_id, care_id);
});
router.delete('/delcare', async (ctx, next) => {
  var { user_id, care_id} = ctx.request.body;
  ctx.body = await user.delCare(user_id, care_id);
});
router.post('/addcourse', async (ctx, netx) => {
  var { user_id, course_id} = ctx.request.body;
  ctx.body = await user.addCourse(user_id, course_id);
});
router.delete('/delcourse', async (ctx, next) => {
  var { user_id, course_id} = ctx.request.body;
  ctx.body = await user.delCourse(user_id, course_id);
});
router.get('/getusercomm/:user_id', async (ctx, next) => {
  var { user_id } = ctx.params;
  ctx.body = await user.getUsercommByUserid(user_id);
});
router.get('/getsportdata/:user_id', async (ctx, next) => {
  var { user_id } = ctx.params;
  ctx.body = await user.getUserSportdataByUserid(user_id);
});
router.post('/addsportdata', async (ctx, netx) => {
  var { user_id, sport_distance, sport_time, sport_date } = ctx.request.body;
  ctx.body = await user.addSportdata(user_id, sport_distance, sport_time, sport_date);
});
router.post('/getcode', async (ctx, netx) => {
  var { code } = ctx.request.body;
  console.log(ctx.request.body)
  ctx.body = await user.login(code);
});
router.get('/getuserinfo/:user_id', async (ctx, next) => {
  var { user_id } = ctx.params;
  ctx.body = await user.getUserinfoByuserid(user_id);
});


module.exports = router;
